package railRoad;

import java.util.ArrayList;

/**
 * Class that presents Passenger data
 * 
 * @author Rukin Oleg
 * 
 */
public class Passenger {

	private int passenger_id;

	private ArrayList<Ticket> tickets;

	private String surname;
	private String name;

	public Passenger() {
		this.passenger_id = -1;
		this.tickets = null;
		this.surname = null;
		this.name = null;
	}

	public Passenger(int passenger_id, ArrayList<Ticket> tickets,
			String surname, String name) {
		super();
		this.passenger_id = passenger_id;
		this.tickets = tickets;
		this.surname = surname;
		this.name = name;
	}

	public int getPassenger_id() {
		return passenger_id;
	}

	public void setPassenger_id(int passenger_id) {
		this.passenger_id = passenger_id;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Ticket getTicketAt(int index) {
		return tickets.get(index);
	}

	public int size() {
		return tickets.size();
	}

	/**
	 * Method to add ticket
	 * 
	 * @param ticket
	 *            Ticket to add
	 * @return TRUE if add other FALSE
	 */
	public boolean addTicket(Ticket ticket) {
		if (tickets == null)
			tickets = new ArrayList<Ticket>();

		boolean rez = ticket.check();

		if (rez) {
			ticket.setType(TicketType.RESERVED.ordinal());
			this.tickets.add(ticket);
		}

		return rez;
	}// addTicket

	/**
	 * Method to replace ticket
	 * 
	 * @param ticket
	 *            Ticket to remove
	 */
	public void replaceTicket(Ticket ticket) {
		this.tickets.remove(ticket);
		ticket.setType(TicketType.NONE.ordinal());
		ticket.returnTicket();
	}// replaceTicket

}
